﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using SalePartial.BLL;
using SalePartial.Model;
using SalePartial.Utility;
using XunPan.Web.Globals;
using System.IO;
using System.Data;

public partial class Trade_Events_event_item : System.Web.UI.Page
{
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {

            ////■■■■■テストため■■■■
            //UserBLL.StoreUserInfoToSession("j@j10.com");

            if (HttpContext.Current.Session["InquiryID"] != null)
                {
                    string InqiryID = (string)HttpContext.Current.Session["InquiryID"];
                    //ltrEventID.Text = eventid;
                    //XPInquiryEvent xpInqu = new XPInquiryEvent();
                    //XPInquiryEventInfo xpevent = xpInqu.GetXPInquiryEvent(new Guid(InqiryID));

                    SqlDataSource1.SelectParameters["InquiryID"].DefaultValue = InqiryID;
                    MembershipUserCollection userList = Membership.FindUsersByEmail(User.Identity.Name);
                    if (userList == null)
                    {
                        Response.Redirect(GlobalSetting.UrlHomePage, true);
                    }
                    //SqlDataSource1.SelectParameters["UserID"].DefaultValue = userList[User.Identity.Name].ProviderUserKey.ToString();

                    SqlDataSource2.SelectParameters["InquiryID"].DefaultValue = InqiryID;


                }

                //SqlDataSource1.SelectParameters("InquiryID").DefaultValue = "bfab11b4-b021-4347-824d-26b33c7b733a"
                //SqlDataSource2.SelectParameters("InquiryID").DefaultValue = "bfab11b4-b021-4347-824d-26b33c7b733a"
           
        }
    }

    protected string GetCurrencyName(string code)
    {
        //FIXME:
        return GlobalUtility.ParseCurrencyCode(code,null);
    }
    protected string GetProcessName(string code, int type)
    {
        //FIXME:
        return GlobalUtility.ParseProcessCode(code, type, null);
    }

    protected void rptBindInquiry_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
    {
       
                string filepath = Server.MapPath((string)e.CommandArgument);



                if (File.Exists(filepath))
                {
                    string fileName = Path.GetFileName(filepath);
                    FileStream MyFileStream = new FileStream(filepath, FileMode.Open);
                    long fileSize = MyFileStream.Length;
                    Context.Server.ScriptTimeout = 600;
                    Context.Response.Buffer = true;
                    Context.Response.Clear();
                    Context.Response.ContentType = "application/octet-stream";
                    Context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\";");
                    Context.Response.AddHeader("Content-Length", Convert.ToInt32(fileSize).ToString());
                    byte[] fileBuffer = new byte[Convert.ToInt32(fileSize) + 1];
                    MyFileStream.Read(fileBuffer, 0, Convert.ToInt32(fileSize));
                    MyFileStream.Close();

                    Context.Response.BinaryWrite(fileBuffer);

                    // End the response
                    Context.Response.End();
                }
               
        }


    }

